home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / mathematica / tex-mma.tar_z / tex-mma / psfig.sty < prev    next >
Text File  |  1991-01-30  |  10KB  |  391 lines

  1. % Psfig/TeX Release 1.2
  2. % dvips version
  3. % psfig.sty version (omit @ -> 11) --- Dan Dill 5/24/90
  4. %
  5. % All software, documentation, and related files in this distribution of
  6. % psfig/tex are Copyright 1987, 1988 Trevor J. Darrell
  7. %
  8. % Permission is granted for use and non-profit distribution of psfig/tex 
  9. % providing that this notice be clearly maintained, but the right to
  10. % distribute any portion of psfig/tex for profit or as part of any commercial
  11. % product is specifically reserved for the author.
  12. %
  13. % $Header: psfig.tex,v 1.9 88/01/08 17:42:01 trevor Exp $
  14. % $Source: $
  15. %
  16. % Thanks to Greg Hager (GDH) and Ned Batchelder for their contributions
  17. % to this project.
  18. %
  19. %\catcode`\@=11\relax % Omit in psfig.sty
  20. \newwrite\@unused
  21. \def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
  22. \typeout{psfig/tex 1.2-dvips}
  23.  
  24.  
  25. %% Here's how you define your figure path.  Should be set up with null
  26. %% default and a user useable definition.
  27.  
  28. \def\figurepath{./}
  29. \def\psfigurepath#1{\edef\figurepath{#1}}
  30.  
  31. %
  32. % @psdo control structure -- similar to Latex @for.
  33. % I redefined these with different names so that psfig can
  34. % be used with TeX as well as LaTeX, and so that it will not 
  35. % be vunerable to future changes in LaTeX's internal
  36. % control structure,
  37. %
  38. \def\@nnil{\@nil}
  39. \def\@empty{}
  40. \def\@psdonoop#1\@@#2#3{}
  41. \def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  42.     \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
  43. \def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  44.        #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
  45. \def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  46.        \let\@nextwhile=\@psdonoop \else
  47.       #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
  48. \def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  49.     \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
  50. \def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  51.        \let\@nextwhile=\@psdonoop \else
  52.       #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
  53. %
  54. \def\psdraft{
  55.     \def\@psdraft{0}
  56.     %\typeout{draft level now is \@psdraft \space . }
  57. }
  58. \def\psfull{
  59.     \def\@psdraft{100}
  60.     %\typeout{draft level now is \@psdraft \space . }
  61. }
  62. \psfull
  63. \newif\if@prologfile
  64. \newif\if@postlogfile
  65. \newif\if@noisy
  66. \def\pssilent{
  67.     \@noisyfalse
  68. }
  69. \def\psnoisy{
  70.     \@noisytrue
  71. }
  72. \psnoisy
  73. %%% These are for the option list.
  74. %%% A specification of the form a = b maps to calling \@p@@sa{b}
  75. \newif\if@bbllx
  76. \newif\if@bblly
  77. \newif\if@bburx
  78. \newif\if@bbury
  79. \newif\if@height
  80. \newif\if@width
  81. \newif\if@rheight
  82. \newif\if@rwidth
  83. \newif\if@clip
  84. \newif\if@verbose
  85. \def\@p@@sclip#1{\@cliptrue}
  86.  
  87. %%% GDH 7/26/87 -- changed so that it first looks in the local directory,
  88. %%% then in a specified global directory for the ps file.
  89.  
  90. \def\@p@@sfile#1{\def\@p@sfile{null}%
  91.             \openin1=#1
  92.         \ifeof1\closein1%
  93.                \openin1=\figurepath#1
  94.             \ifeof1\typeout{Error, File #1 not found}
  95.             \else\closein1
  96.                 \edef\@p@sfile{\figurepath#1}%
  97.                         \fi%
  98.          \else\closein1%
  99.                \def\@p@sfile{#1}%
  100.          \fi}
  101. \def\@p@@sfigure#1{\def\@p@sfile{null}%
  102.             \openin1=#1
  103.         \ifeof1\closein1%
  104.                \openin1=\figurepath#1
  105.             \ifeof1\typeout{Error, File #1 not found}
  106.             \else\closein1
  107.                 \def\@p@sfile{\figurepath#1}%
  108.                         \fi%
  109.          \else\closein1%
  110.                \def\@p@sfile{#1}%
  111.          \fi}
  112.  
  113. \def\@p@@sbbllx#1{
  114.         %\typeout{bbllx is #1}
  115.         \@bbllxtrue
  116.         \dimen100=#1
  117.         \edef\@p@sbbllx{\number\dimen100}
  118. }
  119. \def\@p@@sbblly#1{
  120.         %\typeout{bblly is #1}
  121.         \@bbllytrue
  122.         \dimen100=#1
  123.         \edef\@p@sbblly{\number\dimen100}
  124. }
  125. \def\@p@@sbburx#1{
  126.         %\typeout{bburx is #1}
  127.         \@bburxtrue
  128.         \dimen100=#1
  129.         \edef\@p@sbburx{\number\dimen100}
  130. }
  131. \def\@p@@sbbury#1{
  132.         %\typeout{bbury is #1}
  133.         \@bburytrue
  134.         \dimen100=#1
  135.         \edef\@p@sbbury{\number\dimen100}
  136. }
  137. \def\@p@@sheight#1{
  138.         \@heighttrue
  139.         \dimen100=#1
  140.            \edef\@p@sheight{\number\dimen100}
  141.         %\typeout{Height is \@p@sheight}
  142. }
  143. \def\@p@@swidth#1{
  144.         %\typeout{Width is #1}
  145.         \@widthtrue
  146.         \dimen100=#1
  147.         \edef\@p@swidth{\number\dimen100}
  148. }
  149. \def\@p@@srheight#1{
  150.         %\typeout{Reserved height is #1}
  151.         \@rheighttrue
  152.         \dimen100=#1
  153.         \edef\@p@srheight{\number\dimen100}
  154. }
  155. \def\@p@@srwidth#1{
  156.         %\typeout{Reserved width is #1}
  157.         \@rwidthtrue
  158.         \dimen100=#1
  159.         \edef\@p@srwidth{\number\dimen100}
  160. }
  161. \def\@p@@ssilent#1{ 
  162.         \@verbosefalse
  163. }
  164. \def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
  165. \def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
  166. \def\@cs@name#1{\csname #1\endcsname}
  167. \def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
  168. %
  169. % initialize the defaults (size the size of the figure)
  170. %
  171. \def\ps@init@parms{
  172.         \@bbllxfalse \@bbllyfalse
  173.         \@bburxfalse \@bburyfalse
  174.         \@heightfalse \@widthfalse
  175.         \@rheightfalse \@rwidthfalse
  176.         \def\@p@sbbllx{}\def\@p@sbblly{}
  177.         \def\@p@sbburx{}\def\@p@sbbury{}
  178.         \def\@p@sheight{}\def\@p@swidth{}
  179.         \def\@p@srheight{}\def\@p@srwidth{}
  180.         \def\@p@sfile{}
  181.         \def\@p@scost{10}
  182.         \def\@sc{}
  183.         \@prologfilefalse
  184.         \@postlogfilefalse
  185.         \@clipfalse
  186.         \if@noisy
  187.             \@verbosetrue
  188.         \else
  189.             \@verbosefalse
  190.         \fi
  191. }
  192. %
  193. % Go through the options setting things up.
  194. %
  195. \def\parse@ps@parms#1{
  196.          \@psdo\@psfiga:=#1\do
  197.            {\expandafter\@setparms\@psfiga,}}
  198. %
  199. % Compute bb height and width
  200. %
  201. \newif\ifno@bb
  202. \newif\ifnot@eof
  203. \newread\ps@stream
  204. \def\bb@missing{
  205.     \if@verbose{
  206.         \typeout{psfig: searching \@p@sfile \space  for bounding box}
  207.     }\fi
  208.     \openin\ps@stream=\@p@sfile
  209.     \no@bbtrue
  210.     \not@eoftrue
  211.     \catcode`\%=12
  212.     \loop
  213.         \read\ps@stream to \line@in
  214.         \global\toks200=\expandafter{\line@in}
  215.         \ifeof\ps@stream \not@eoffalse \fi
  216.         %\typeout{ looking at :: \the\toks200 }
  217.         \@bbtest{\toks200}
  218.         \if@bbmatch\not@eoffalse\expandafter\bb@cull\the\toks200\fi
  219.     \ifnot@eof \repeat
  220.     \catcode`\%=14
  221. }    
  222. \catcode`\%=12
  223. \newif\if@bbmatch
  224. \def\@bbtest#1{\expandafter\@a@\the#1%%BoundingBox:\@bbtest\@a@}
  225. \long\def\@a@#1%%BoundingBox:#2#3\@a@{\ifx\@bbtest#2\@bbmatchfalse\else\@bbmatchtrue\fi}
  226. \long\def\bb@cull#1 #2 #3 #4 #5 {
  227.     \dimen100=#2 bp\edef\@p@sbbllx{\number\dimen100}
  228.     \dimen100=#3 bp\edef\@p@sbblly{\number\dimen100}
  229.     \dimen100=#4 bp\edef\@p@sbburx{\number\dimen100}
  230.     \dimen100=#5 bp\edef\@p@sbbury{\number\dimen100}
  231.     \no@bbfalse
  232. }
  233. \catcode`\%=14
  234. %
  235. \def\compute@bb{
  236.         \no@bbfalse
  237.         \if@bbllx \else \no@bbtrue \fi
  238.         \if@bblly \else \no@bbtrue \fi
  239.         \if@bburx \else \no@bbtrue \fi
  240.         \if@bbury \else \no@bbtrue \fi
  241.         \ifno@bb \bb@missing \fi
  242.         \ifno@bb \typeout{FATAL ERROR: no bb supplied or found}
  243.             \no-bb-error
  244.         \fi
  245.         %
  246.         \count203=\@p@sbburx
  247.         \count204=\@p@sbbury
  248.         \advance\count203 by -\@p@sbbllx
  249.         \advance\count204 by -\@p@sbblly
  250.         \edef\@bbw{\number\count203}
  251.         \edef\@bbh{\number\count204}
  252.         %\typeout{ bbh = \@bbh, bbw = \@bbw }
  253. }
  254. %
  255. % \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
  256. %    then leaves the result in @result
  257. %
  258. \def\in@hundreds#1#2#3{\count240=#2 \count241=#3
  259.              \count100=\count240    % 100 is first digit #2/#3
  260.              \divide\count100 by \count241
  261.              \count101=\count100
  262.              \multiply\count101 by \count241
  263.              \advance\count240 by -\count101
  264.              \multiply\count240 by 10
  265.              \count101=\count240    %101 is second digit of #2/#3
  266.              \divide\count101 by \count241
  267.              \count102=\count101
  268.              \multiply\count102 by \count241
  269.              \advance\count240 by -\count102
  270.              \multiply\count240 by 10
  271.              \count102=\count240    % 102 is the third digit
  272.              \divide\count102 by \count241
  273.              \count200=#1\count205=0
  274.              \count201=\count200
  275.             \multiply\count201 by \count100
  276.              \advance\count205 by \count201
  277.              \count201=\count200
  278.             \divide\count201 by 10
  279.             \multiply\count201 by \count101
  280.             \advance\count205 by \count201
  281.             %
  282.              \count201=\count200
  283.             \divide\count201 by 100
  284.             \multiply\count201 by \count102
  285.             \advance\count205 by \count201
  286.             %
  287.              \edef\@result{\number\count205}
  288. }
  289. \def\compute@wfromh{
  290.         % computing : width = height * (bbw / bbh)
  291.         \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
  292.         %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  293.         \edef\@p@swidth{\@result}
  294.         %\typeout{w from h: width is \@p@swidth}
  295. }
  296. \def\compute@hfromw{
  297.         % computing : height = width * (bbh / bbw)
  298.         \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
  299.         %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  300.         \edef\@p@sheight{\@result}
  301.         %\typeout{h from w : height is \@p@sheight}
  302. }
  303. \def\compute@handw{
  304.         \if@height 
  305.             \if@width
  306.             \else
  307.                 \compute@wfromh
  308.             \fi
  309.         \else 
  310.             \if@width
  311.                 \compute@hfromw
  312.             \else
  313.                 \edef\@p@sheight{\@bbh}
  314.                 \edef\@p@swidth{\@bbw}
  315.             \fi
  316.         \fi
  317. }
  318. \def\compute@resv{
  319.         \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  320.         \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
  321. }
  322. %        
  323. % Compute any missing values
  324. \def\compute@sizes{
  325.     \compute@bb
  326.     \compute@handw
  327.     \compute@resv
  328. }
  329. %
  330. % \psfig
  331. % usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
  332. %            rheight=, rwidth=, clip=}
  333. %
  334. % "clip=" is a switch and takes no value, but the `=' must be present.
  335. \def\psfig#1{\vbox {
  336.     % do a zero width hard space so that a single
  337.     % \psfig in a centering enviornment will behave nicely
  338.     %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  339.     %
  340.     \ps@init@parms
  341.     \parse@ps@parms{#1}
  342.     \compute@sizes
  343.     %
  344.     \ifnum\@p@scost<\@psdraft{
  345.         \if@verbose{
  346.             \typeout{psfig: including \@p@sfile \space }
  347.         }\fi
  348.         %
  349.         \special{ps::[begin]     \@p@swidth \space \@p@sheight \space
  350.                 \@p@sbbllx \space \@p@sbblly \space
  351.                 \@p@sbburx \space \@p@sbbury \space
  352.                 startTexFig \space }
  353.         \if@clip{
  354.             \if@verbose{
  355.                 \typeout{(clip)}
  356.             }\fi
  357.             \special{ps:: doclip \space }
  358.         }\fi
  359.         \if@prologfile
  360.             \special{ps: plotfile \@prologfileval \space } \fi
  361.         \special{ps: plotfile \@p@sfile \space }
  362.         \if@postlogfile
  363.             \special{ps: plotfile \@postlogfileval \space } \fi
  364.         \special{ps::[end] endTexFig \space }
  365.         % Create the vbox to reserve the space for the figure
  366.         \vbox to \@p@srheight true sp{
  367.             \hbox to \@p@srwidth true sp{
  368.                 \hss
  369.             }
  370.         \vss
  371.         }
  372.     }\else{
  373.         % draft figure, just reserve the space and print the
  374.         % path name.
  375.         \vbox to \@p@srheight true sp{
  376.         \vss
  377.             \hbox to \@p@srwidth true sp{
  378.                 \hss
  379.                 \if@verbose{
  380.                     \@p@sfile
  381.                 }\fi
  382.                 \hss
  383.             }
  384.         \vss
  385.         }
  386.     }\fi
  387. }}
  388. \def\psglobal{\typeout{psfig: PSGLOBAL is OBSOLETE; use psprint -m instead}}
  389. %\catcode`\@=12\relax % Omit in psfig.sty
  390.